< previous page page_203 next page >

Page 203
Solution 17
The DEVMODE Is in the Details
One thing you'll quickly learn when working with API functions is to read the documentation very, very carefully. Just following a tip or technique published in a magazine or on the Internet is not terribly reliable, because you never know if the author took the time to read the documentation and test the technique beyond one simple application.
In this case, you can find the secret in two places.1
In the description of the DocumentProperties function in my Win32 API book, you'll find the following description for the pDevModeOutput parameter:
7017a6ead0e3c4111b47a554df321e9f.gif 7017a6ead0e3c4111b47a554df321e9f.gif
LongPointer to a DEVMODE data structure for the device. . . . Note that this pointer must refer to a buffer that is large enough to include the private printer driver data as well as the standard DEVMODE structure. Use the agGetAddressForObjectfunction (or VarPtr operator) to obtain the address of a structure or byte array, or pass the address of a memory block allocated using GlobalAlloc.
7017a6ead0e3c4111b47a554df321e9f.gif 7017a6ead0e3c4111b47a554df321e9f.gif
If fMode is zero, this function returns the size of the DEVMODE structure for this device. Note that this structure may be larger than the size specified in the type definition file API32.TXT.
If you look in the Win32 SDK, you'll find the following in the comments section:
7017a6ead0e3c4111b47a554df321e9f.gif 7017a6ead0e3c4111b47a554df321e9f.gif
If the fMode parameter is zero, the return value is the size of the buffer required to contain the printer driver initialization data. Note that this buffer can be larger than a DEVMODE structure if the printer driver appends private data to the structure.
7017a6ead0e3c4111b47a554df321e9f.gif 7017a6ead0e3c4111b47a554df321e9f.gif
Note that the DEVMODE structure actually used by a printer driver contains the device-independent part (as defined above) followed by a driver-specific part that varies in size and content with each driver and driver
7017a6ead0e3c4111b47a554df321e9f.gif 7017a6ead0e3c4111b47a554df321e9f.gif
1 You may think it unfair that this puzzle requires you to look in outside documentation in order to find a solution. But the intent of this book is, in part, to teach you the habits necessary to handle all of these types of problems, and you can't do serious API programming without some sort of reference. Besides, the hints for this puzzle in Appendix A clearly indicated that you would need to look elsewhere for further information.

 
< previous page page_203 next page >